<template>
    <div class="form-group">
        <label class="col-sm-4 control-label">检查项目：</label>
        <div class="col-sm-8" :class="$route.path=='/safety/trouble' ? 'col8' :''">
            <select class="form-control select2" style="width: 100%;" v-model="selected" @change="$emit('input', $event.target.value)">
                <option value="" disabled selected style='display:none;' v-if="$route.path=='/safety/addTrouble'" >请选择</option>
                <option value="" v-if="$route.path=='/safety/trouble'">全部</option>
                <option v-for="lst in itemsList" :value="lst.value" :key="lst.value">{{lst.name}}</option>
            </select>

        </div>
    </div>
</template>

<script>

export default {
    props: {
        value: [String, Number],
    },
    data() {
        return {
            itemsList: [],
            selected: this.value
        };
    },
    watch: {
        value() {
            this.selected = this.value;
        }
    },
    mounted(){
        this.getItems()
    },
    methods: {
        getItems() {
            this.$api.safe.items().then(res => {
                if (res.success) {
                    // console.log(res);
                    this.itemsList=res.data
                }
            });
        },
    }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.control-label {
  padding: 0;
  line-height: 34px;
  text-align: right;
}
input,
select,
textarea {
  border-radius: 5px;
}
.col8{
    padding: 0
}
</style>
